var { default: Memcached } = require('memcached-client');
const {resolve}  = require('path');
const YAML = require('yamljs');
const config = YAML.load(resolve(__dirname,"..","project.yaml"))
const {memcache: {host,port}} = config;
const cli = new Memcached(host, port);

async function get(key){
    const conn = await cli.connect();
    const data = await conn.get(key);
    await conn.close();
    return data[key];
}

async function set(key,value,expire){
    const conn = await cli.connect();
    const result = await conn.set(key, value, false, expire);
    await conn.close();
    return result=="STORED";
}

module.exports = {
    get
    , set
}